//
//  InviteContentLargeView.m
//  FbeeAPP
//
//  Created by dev-m on 2018/3/21.
//  Copyright © 2018年 mohao. All rights reserved.
//

#import "InviteContentLargeView.h"
#import "BeePhotoImageView.h"
#import "UIImageView+WebCache.h"
#import "BeeGroupListObj.h"
#import "InviteObj.h"

@interface InviteContentLargeView()
{
    
    BeeGroupListObj *beeObj;
    UIView *contentV;
    UILabel *sloganL;
    
    //content
    UIImageView *bgView;
    UIImageView *logoView;
    
    UILabel *beeName;
    UILabel *limitInfo;
    UILabel *beeTipsInfo;
    UIView *codeView;
    
    //底部
    BeePhotoImageView *photo;
    UILabel *nickName;
    UILabel *bottomInfo;
    UIImageView *qrCode;
    
    
    
}
@end

@implementation InviteContentLargeView

-(instancetype)initWithFrame:(CGRect)frame obj:(BeeGroupListObj *)obj
{
    self = [super initWithFrame:frame];
    
    if (self) {
        beeObj = obj;
        [self buildView];
    }
    
    return self;
}

-(void)buildView
{
    UIImageView *bgview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, IPHONEWIDTH, IPHONEHEIGHT)];
    [bgview setContentScaleFactor:[[UIScreen mainScreen] scale]];
    bgview.contentMode =  UIViewContentModeScaleAspectFill;
    bgview.autoresizingMask = UIViewAutoresizingFlexibleHeight;
    bgview.clipsToBounds  = YES;
    [bgview sd_setImageWithURL:[NSURL URLWithString:beeObj.logoUrl]];
    [self addSubview:bgview];
    
    UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
    effectView.frame = CGRectMake(0, 0, IPHONEWIDTH, IPHONEHEIGHT);
    [self addSubview:effectView];
    
    
    contentV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 345*UISCALE, 425*UISCALE)];
    contentV.top = 25;
    contentV.centerX = self.centerX;
    [self addSubview:contentV];
    
    {
        bgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, contentV.width, contentV.height)];
        UIImage *img = [UIImage imageNamed:@"invite_bg"];
        img = [img resizableImageWithCapInsets:UIEdgeInsetsMake(80, 10, 80, 10) resizingMode:UIImageResizingModeStretch];
        bgView.image = img;
        [contentV addSubview:bgView];
        
        logoView = [[UIImageView alloc] initWithFrame:CGRectMake(12.5, 12.5, contentV.width - 25, 140 * UISCALE)];
        //平铺
        [logoView setContentScaleFactor:[[UIScreen mainScreen] scale]];
        logoView.contentMode =  UIViewContentModeScaleAspectFill;
        logoView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
        logoView.clipsToBounds  = YES;
        [logoView sd_setImageWithURL:[NSURL URLWithString:beeObj.logoUrl]];
        [contentV addSubview:logoView];
        
        UIImageView *blackV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, logoView.width, logoView.height)];
        blackV.backgroundColor = UIColorFromRGBA(0x000000, 0.5);
        [logoView addSubview:blackV];
        
        beeName = [UILabel makeLabel:^(TTLabelExtend *make) {
            make.addTextColor(COLOR_WHITE).addFont([UIFont boldSystemFontOfSize:24.0f]);
            make.addText(beeObj.groupName);
            [make sizeToFit];
            make.center = logoView.center;
            [contentV addSubview:make];
        }];
        
        limitInfo = [UILabel makeLabel:^(TTLabelExtend *make) {
            make.addTextColor(UIColorFromRGB(0xF7B62D)).addFont([UIFont systemFontOfSize:16.0f]);
            make.addText(beeObj.inviteObj.rewardLimitTips);
            [make sizeToFit];
            make.top = logoView.bottom + 20;
            make.centerX = self.width/2;
            [contentV addSubview:make];
        }];
        
        beeTipsInfo = [UILabel makeLabel:^(TTLabelExtend *make) {
            make.addTextColor(UIColorFromRGB(0xF7B62D)).addFont([UIFont systemFontOfSize:25.0f]);
            make.addText(beeObj.inviteObj.rewardBeeTips);
            [make sizeToFit];
            make.top = limitInfo.bottom + 15;
            make.centerX = self.width/2;
            [contentV addSubview:make];
        }];
        
        codeView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 131*UISCALE, 70*UISCALE)];
        codeView.centerX = contentV.width/2;
        codeView.bottom = contentV.height - 100*UISCALE;
        [contentV addSubview:codeView];
        {
            UIImageView *bg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, codeView.width, codeView.height)];
            bg.image = [UIImage imageNamed:@"invite_codeframe"];
            [codeView addSubview:bg];
            
            UILabel *codeL = [UILabel makeLabel:^(TTLabelExtend *make) {
                make.addTextColor(FBEE_COLOR_INFO).addFont([UIFont systemFontOfSize:25.0f]);
                make.addText(beeObj.inviteCode);
                [make sizeToFit];
                make.centerX = codeView.width/2;
                make.top = 10;
                [codeView addSubview:make];
            }];
            
            UILabel *code2L = [UILabel makeLabel:^(TTLabelExtend *make) {
                make.addTextColor(FBEE_COLOR_INFO).addFont([UIFont systemFontOfSize:14.0f]);
                make.addText(@"邀请码");
                [make sizeToFit];
                make.centerX = codeView.width/2;
                make.top = codeL.bottom+5;
                [codeView addSubview:make];
            }];
        }
        
        
        
        photo = [[BeePhotoImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 40) photoStyle:BeePhotoDefaultStyle];
        [photo setTitle:[UserInfoManager sharedManager].nickName];
        photo.left = 25;
        photo.bottom = contentV.height - 19;
        [contentV addSubview:photo];
        
        nickName = [UILabel makeLabel:^(TTLabelExtend *make) {
            make.addTextColor(FBEE_COLOR_TEXT).addFont([UIFont systemFontOfSize:16.0f]);
            make.addText([UserInfoManager sharedManager].nickName);
            [make sizeToFit];
            make.top = photo.top;
            make.left = photo.right + 12;
            [contentV addSubview:make];
        }];
        
        bottomInfo = [UILabel makeLabel:^(TTLabelExtend *make) {
            make.addTextColor(FBEE_COLOR_INFO).addFont([UIFont systemFontOfSize:12.0f]);
            make.addText([NSString stringWithFormat:@"第%@位成员@%@",beeObj.joinSeq,beeObj.groupName]);
            [make sizeToFit];
            make.top = nickName.bottom + 5;
            make.left = photo.right + 12;
            [contentV addSubview:make];
        }];
        
    }
    
    
    qrCode = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 90*UISCALE, 90*UISCALE)];
    UIImage *qrImg = [UIImage encodeQRImageWithContent:beeObj.inviteObj.shareUrl size:CGSizeMake(200, 200)];
    qrCode.image = qrImg;
    qrCode.top = contentV.bottom + 30*UISCALE;
    qrCode.centerX = self.centerX;
    [self addSubview:qrCode];
    
    UIImageView *qrBg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 104*UISCALE, 104*UISCALE)];
    qrBg.backgroundColor = COLOR_WHITE;
    qrBg.center = qrCode.center;
    qrBg.layer.cornerRadius = 10;
    [self addSubview:qrBg];
    [self bringSubviewToFront:qrCode];
    
    
    UILabel *qrInfo = [UILabel makeLabel:^(TTLabelExtend *make) {
        make.addTextColor(COLOR_WHITE).addFont([UIFont systemFontOfSize:12.0f]);
        make.addText(@"识别二维码加入");
        [make sizeToFit];
        make.top = qrBg.bottom + 10*UISCALE;
        make.centerX = self.centerX;
        [self addSubview:make];
    }];
    
    sloganL = [UILabel makeLabel:^(TTLabelExtend *make) {
        make.addTextColor(COLOR_WHITE).addFont([UIFont systemFontOfSize:12.0f]);
        make.addText(@"Fbee.one 10000万糖果区块链社区");
        [make sizeToFit];
        make.top = qrInfo.bottom + 10*UISCALE;
        make.centerX = self.centerX;
        [self addSubview:make];
    }];
    
}

@end
